$(function () {

  // 1.自定义校验规则
  let form = layui.form
  form.verify({
    pwd: [
      /^[\S]{6,15}$/,
      "密码必须是6-15位的非空字符串"
    ],
    newPwd: function (value) {
      let v1 = $("[name=oldPwd]").val()
      if (value == v1) {
        return "新旧密码不能相同"
      }
    },
    rePwd: function (value) {
      let v2 = $("[name=newPwd]").val()
      if (value != v2) {
        return "两次密码不一致"
      }
    }




  })

  // 2.修改密码
  $("#formPwd").on("submit", function (e) {
    e.preventDefault()
    axios({
      url: '/my/updatepwd',
      method: 'post',
      data: $(this).serialize()

    }).then(res => {
      //成功回调
      // console.log(res)
      if (res.data.status != 0) {
        return layui.layer.msg(res.data.message)
      }
      layer.msg("恭喜你,修改密码成功")
      // 清空表单
      $("#formPwd")[0].reset()
      // 跳转登录页
      window.parent.location.href = "/login.html"

    });
  })









})